﻿using ApiManage.Models.zyhModels;
using ApiManage.Service.MsSql.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace ApiManage.Service.MsSql.Service
{
    public class SysMessageService : BaseService, ISysMessageService
    {

        public List<SysMessage> GetList(Expression<Func<SysMessage, bool>> where) => _zyhContext.SysMessage.Where(where).ToList();

        public void Insert(SysMessage param)
        {
            _zyhContext.SysMessage.Add(param);
            _zyhContext.SaveChanges();
        }

        public void Update(SysMessage param)
        {
            var user = _zyhContext.SysMessage.FirstOrDefault(o => o.Id == param.Id);
            user.Title = param.Title;
            user.Content = param.Content;
            user.Type = param.Type;
            user.ReceiptType = param.ReceiptType;
            user.Recipient = param.Recipient;
            user.IsTop = param.IsTop;
            user.Mark = param.Mark;
            _zyhContext.SaveChanges();
        }
        public void Delete(int id)
        {
            var message = _zyhContext.SysMessage.FirstOrDefault(o => o.Id == id);
            message.Mark = 9;
            _zyhContext.SaveChanges();
        }
    }
}
